package com.webbit.swing;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

/**
 *
 * @author webbyit
 */
public class AboutDialog extends javax.swing.JDialog {

    /** Creates new form AboutDialog */
    public AboutDialog(java.awt.Frame parent, boolean modal, String version, String buildDate, String copyright) {
        super(parent, modal);
        initComponents();
        setProductDetails(version, buildDate, copyright);
        setJavaDetails();
    }

    private void setProductDetails(String version, String buildDate, String copyright) {
        versionTF.setText(version);
        buildDateTF.setText(buildDate);
        copyrightTF.setText(copyright);
    }

    private void setJavaDetails() {
        // Java specific details
        osTF.setText(System.getProperty("os.name") + " version "
                + System.getProperty("os.version") + " running on "
                + System.getProperty("os.arch"));
        javaVersionTF.setText(System.getProperty("java.version"));
        vmVersionTF.setText(System.getProperty("java.vm.name") + " "
                + System.getProperty("java.vm.version"));
        vmVendorTF.setText(System.getProperty("java.specification.vendor"));
        javaHomeTF.setText(System.getProperty("java.home"));
        localeTF.setText(System.getProperty("user.language") + "_"
                + System.getProperty("user.country"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        okButton = new JButton();
        jSeparator1 = new JSeparator();
        tabbedPane = new JTabbedPane();
        applicationPanel = new JPanel();
        jPanel2 = new JPanel();
        copyrightTF = new JLabel();
        versionLb = new JLabel();
        versionTF = new JLabel();
        copyrightLb = new JLabel();
        buildDateLb = new JLabel();
        buildDateTF = new JLabel();
        javaPanel = new JPanel();
        jPanel1 = new JPanel();
        osLb = new JLabel();
        localeTF = new JLabel();
        osTF = new JLabel();
        localeLb = new JLabel();
        vmVersionTF = new JLabel();
        javaHomeTF = new JLabel();
        javaVersionTF = new JLabel();
        javaHomeLb = new JLabel();
        vmvLb = new JLabel();
        javaVersionLb = new JLabel();
        vmVendorTF = new JLabel();
        vmLb = new JLabel();

        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("About");

        okButton.setMnemonic('O');
        okButton.setText("OK");
        okButton.setName("okButton"); // NOI18N
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        jSeparator1.setName("jSeparator1"); // NOI18N

        tabbedPane.setName("tabbedPane"); // NOI18N

        applicationPanel.setName("applicationPanel"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        copyrightTF.setName("copyrightTF"); // NOI18N

        versionLb.setText("Version:");
        versionLb.setName("versionLb"); // NOI18N

        versionTF.setText(" ");
        versionTF.setName("versionTF"); // NOI18N

        copyrightLb.setText("Copyright:");
        copyrightLb.setName("copyrightLb"); // NOI18N

        buildDateLb.setText("Build Date:");
        buildDateLb.setName("buildDateLb"); // NOI18N

        buildDateTF.setText(" ");
        buildDateTF.setName("buildDateTF"); // NOI18N

        GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(versionLb, Alignment.TRAILING)
                    .addComponent(buildDateLb, Alignment.TRAILING)
                    .addComponent(copyrightLb, Alignment.TRAILING))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING, false)
                    .addComponent(buildDateTF, GroupLayout.PREFERRED_SIZE, 537, GroupLayout.PREFERRED_SIZE)
                    .addComponent(versionTF, GroupLayout.PREFERRED_SIZE, 537, GroupLayout.PREFERRED_SIZE)
                    .addComponent(copyrightTF, GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {buildDateTF, copyrightTF, versionTF});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(versionLb)
                    .addComponent(versionTF))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(buildDateLb)
                    .addComponent(buildDateTF))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(copyrightLb)
                    .addComponent(copyrightTF))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(SwingConstants.VERTICAL, new Component[] {buildDateTF, copyrightTF, versionTF});

        GroupLayout applicationPanelLayout = new GroupLayout(applicationPanel);
        applicationPanel.setLayout(applicationPanelLayout);
        applicationPanelLayout.setHorizontalGroup(
            applicationPanelLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(jPanel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        applicationPanelLayout.setVerticalGroup(
            applicationPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(applicationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(106, 106, 106))
        );

        tabbedPane.addTab("Application", applicationPanel);

        javaPanel.setName("javaPanel"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        osLb.setText("Operating System:");
        osLb.setName("osLb"); // NOI18N

        localeTF.setText(" ");
        localeTF.setName("localeTF"); // NOI18N

        osTF.setText(" ");
        osTF.setName("osTF"); // NOI18N

        localeLb.setText("Locale:");
        localeLb.setName("localeLb"); // NOI18N

        vmVersionTF.setText(" ");
        vmVersionTF.setName("vmVersionTF"); // NOI18N

        javaHomeTF.setText(" ");
        javaHomeTF.setName("javaHomeTF"); // NOI18N

        javaVersionTF.setText(" ");
        javaVersionTF.setName("javaVersionTF"); // NOI18N

        javaHomeLb.setText("Java Home:");
        javaHomeLb.setName("javaHomeLb"); // NOI18N

        vmvLb.setText("VM Vendor:");
        vmvLb.setName("vmvLb"); // NOI18N

        javaVersionLb.setText("Java Version:");
        javaVersionLb.setName("javaVersionLb"); // NOI18N

        vmVendorTF.setText(" ");
        vmVendorTF.setName("vmVendorTF"); // NOI18N

        vmLb.setText("VM Version:");
        vmLb.setName("vmLb"); // NOI18N

        GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(osLb, Alignment.TRAILING)
                    .addComponent(javaVersionLb, Alignment.TRAILING)
                    .addComponent(vmLb, Alignment.TRAILING)
                    .addComponent(vmvLb, Alignment.TRAILING)
                    .addComponent(javaHomeLb, Alignment.TRAILING)
                    .addComponent(localeLb, Alignment.TRAILING))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.TRAILING)
                    .addComponent(osTF, GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(vmVersionTF, GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(vmVendorTF, GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(javaHomeTF, GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(localeTF, GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
                    .addComponent(javaVersionTF, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(osLb)
                    .addComponent(osTF))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(javaVersionLb)
                    .addComponent(javaVersionTF))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(vmLb)
                    .addComponent(vmVersionTF))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(vmvLb)
                    .addComponent(vmVendorTF))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(javaHomeLb)
                    .addComponent(javaHomeTF))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(localeLb)
                    .addComponent(localeTF))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        GroupLayout javaPanelLayout = new GroupLayout(javaPanel);
        javaPanel.setLayout(javaPanelLayout);
        javaPanelLayout.setHorizontalGroup(
            javaPanelLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        javaPanelLayout.setVerticalGroup(
            javaPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(javaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(13, 13, 13))
        );

        tabbedPane.addTab("Java", javaPanel);

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(tabbedPane, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE)
                    .addComponent(jSeparator1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE)
                    .addComponent(okButton, Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(okButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        dispose();
    }//GEN-LAST:event_okButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                AboutDialog dialog = new AboutDialog(new javax.swing.JFrame(), true, "1.0", "14:03:01 15th March 2011",
                        "© 2011 Webby IT Ltd");
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected JPanel applicationPanel;
    protected JLabel buildDateLb;
    protected JLabel buildDateTF;
    protected JLabel copyrightLb;
    protected JLabel copyrightTF;
    protected JPanel jPanel1;
    protected JPanel jPanel2;
    protected JSeparator jSeparator1;
    protected JLabel javaHomeLb;
    protected JLabel javaHomeTF;
    protected JPanel javaPanel;
    protected JLabel javaVersionLb;
    protected JLabel javaVersionTF;
    protected JLabel localeLb;
    protected JLabel localeTF;
    protected JButton okButton;
    protected JLabel osLb;
    protected JLabel osTF;
    protected JTabbedPane tabbedPane;
    protected JLabel versionLb;
    protected JLabel versionTF;
    protected JLabel vmLb;
    protected JLabel vmVendorTF;
    protected JLabel vmVersionTF;
    protected JLabel vmvLb;
    // End of variables declaration//GEN-END:variables
}
